<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>细节-使用ref</title>
    <script src="vue.js"></script>
</head>
<body>
    <!-- 有时候情况  我们不得不操作dom，我们使用ref操作dom -->
    <div id="app">
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <div>{{total}}</div>
    </div>
    <script>
        Vue.component("counter", {
            data : function(){
                return {
                  number : 0
                }
            },
            template : "<div @click='handleClick'>{{number}}</div>",
            methods : {
                handleClick : function () {
                    this.number ++
                    this.$emit("change")
                }
            }
        })

        var vm = new Vue({
            el : "#app",
            data : {
                total : 0
            },
            methods : {
                handleChange : function(){
                    this.total = this.$refs.one.number + this.$refs.two.number
                }
            }
        })
    </script>
</body>
</html>